#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=20;
int p[maxn+1], q[maxn+1], r[maxn+1], s[maxn+1], f[1<<maxn], g[1<<maxn];

int sqr(int a) {return a*a;}

int main() {
    freopen("landmine.in", "r", stdin);
    freopen("check.out", "w", stdout);

    int n;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%d", p+i);
    for (int i=1; i<=n; i++) scanf("%d", q+i);
    for (int i=1; i<=n; i++) scanf("%d", r+i);
    for (int i=1; i<=n; i++) scanf("%d", s+i);

    for (int i=0; i<(1<<n); i++) {
        for (int j=1; j<=n; j++) {
            if (!((i>>(j-1))&1)) {
                int p1, n1, n2;
                for (p1=j-1; p1>0 && ((i>>(p1-1))&1); p1--);
                for (n1=j+1; n1<=n && ((i>>(n1-1))&1); n1++);
                for (n2=n1+1; n2<=n && ((i>>(n2-1)&1)); n2++);
                if (n1>n) n1=0;
                if (n2>n) n2=0;

                int ns=i|(1<<(j-1));
                if (f[ns]<f[i]+sqr(p[p1]-q[j])+sqr(p[j]-r[n1])+sqr(p[n1]-s[n2])) {
                    g[ns] = i;
                }
                f[ns] = max(f[ns], f[i]+sqr(p[p1]-q[j])+sqr(p[j]-r[n1])+sqr(p[n1]-s[n2]));
            }
        }
    }

    printf("%d\n", f[(1<<n)-1]);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
